/**
 * 项目管理信息
 */
CommonUtils.regNamespace("project", "index");

project.index = (function(){
	//定义全局变量
	var _productParams = {
		authorizionList:"",//项目权限
		projectType:"",//生产环境项目类型
		apkId:"",
		platformType:"",//平台类型
		resProject:null,
		currentPage: 1,//当前页,项目列表
		apkCurrentPage:1,//当前页,apk列表
		scriptCurrentPage:1,//当前页,apk列表
		testApkCurrentPage:1,//当前页,testapk列表
		testWebCurrentPage:1,//当前页,web项目列表
		docCurrentPage:1,//当前页,文档管理
        numberOfPages: 3,//分页条展示数
        pageSize:8,//每页展示记录数
        totalPages:0	//记录总数
	};
	_insertProject = function(){
		var projectTitle = $("#projectTitle").val();
		if(projectTitle==null||projectTitle==""){
			alert("项目名称不能为空");
			return;
		}
		var projectType = $("#projectType").find("option:selected").val();//$("#projectType").val();
		if(projectType==null||projectType==""){
			alert("请选择项目类型");
			return;
		}
		var testType = $("#testType").find("option:selected").val();//$("#projectType").val();
		if(testType==null||testType==""){
			alert("请选择测试类型");
			return;
		}
		var platformType = $("#platformType").find("option:selected").val();//$("#projectType").val();
		if(platformType==null||platformType==""){
			alert("请选择平台类型");
			return;
		}
		/*if(projectType==null||projectType==""){
			alert("项目类型不能为空");
			return;
		}*/
		var projectPackage = $("#projectPackage").val();
		if((platformType=="2"||platformType=="3")&&(projectPackage==null)){
			alert("项目包名不能为空");
			return;
		}
		var projectActivity = $("#projectActivity").val();
		if(platformType!="3"&&platformType!="1"&&(projectActivity==null)){
			alert("项目Activity不能为空");
			return;
		}
		var projectLoginUrl = $("#projectLoginUrl").val();
		var projectFlag = $("#projectFlag").find("option:selected").val();
		var projectDesc = $("#projectDesc").val();
		var params = {
				"projectTitle":projectTitle,
				"projectType":projectType,
				"projectPackage":projectPackage,
				"projectActivity":projectActivity,
				"projectLoginUrl":projectLoginUrl,
				"projectDesc":projectDesc,
				"projectFlag":projectFlag,
				"testType":testType,
				"platformType":platformType
		};
		var path = contextPath+"/project/insertProject";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "json",
	        async:false,
	        success:function(respone){
	        	if(respone){
	        		if(respone.code==0){
	        			//跳转到项目列表界面
	        			project.index.changeFunction("project_1","/project/totalProject");
	        		}else if(respone.code=="-1"){
	        			Lobibox.alert('error', {
	                        msg: respone.message
	                    });
	        			window.location.href = contextPath + "/user/login";
	        		}else{
	        			Lobibox.alert('error', {
	                        msg: respone.message
	                    });
	        		}
	        	}else{
	        		alert("创建项目失败");
	        	}
	        },error:function(respone){
	            alert("请求发生错误:"+respone);
	        }
		});
	};
	/**
	 * 修改项目
	 */
	_modifyModel = function(projectId,projectTitle){
		$("#projectId").val(projectId);
		$("#modifyModalLabel").text(projectTitle);
		
		//查询该项目信息
		project.index.queryTheProject(projectId);
		//参数定义
		var project_name = project.index.productParams.resProject.project_name;
		var project_type = project.index.productParams.resProject.project_type;
		var platform_type = project.index.productParams.resProject.platform_type;
		var environment_type =  project.index.productParams.resProject.environment_type;//环境类型
		var project_package = project.index.productParams.resProject.project_package;
		var test_type = project.index.productParams.resProject.test_type;
		var project_main_activity = project.index.productParams.resProject.project_main_activity; 
		var project_login_url = project.index.productParams.resProject.project_login_url; 
		var project_desc = project.index.productParams.resProject.project_desc;
		//查询项目类型
		var options = "";
		var plateOptions = "";
		var params = {};
		var path = contextPath+"/project/queryProjectType";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "json",
	        async:false,
	        success:function(respone){
	        	if(respone){
	        		if(respone.code==0){
	        			//跳转到项目列表界面
	        			$.each(respone.typeList,function(index,list){
	        				if(environment_type=="0"&&environment_type==list.environment_type){
	        					if(project_type==list.share_project_type){
		        					options = options+"<option selected value='"+list.share_project_type+"'>"+list.share_project_name+"</option>";
		        				}else{
		        					options = options+"<option value='"+list.share_project_type+"'>"+list.share_project_name+"</option>";
		        				}
	        				}
	        				if(environment_type=="1"&&environment_type==list.environment_type){
	        					if(project_type==list.share_project_type){
		        					options = options+"<option selected value='"+list.share_project_type+"'>"+list.share_project_name+"</option>";
		        				}else{
		        					options = options+"<option value='"+list.share_project_type+"'>"+list.share_project_name+"</option>";
		        				}
	        				}
	        			});
	        			if(environment_type=="0"){
	        				options = options+"</select><input type='checkbox' checked id='updateEnviromentType' onclick='project.index.updateEnvironmentType("+environment_type+","+project_type+");' style='margin:0 5px;'> <span id='preEnviroment'>生产环境</span></div><br>";
	        			}else{
	        				options = options+"</select><input type='checkbox' id='updateEnviromentType' onclick='project.index.updateEnvironmentType("+environment_type+","+project_type+");' style='margin:0 5px;'> <span id='preEnviroment'>生产环境</span></div><br>";
	        			}
	        		}else{
	        			Lobibox.alert('error', {
	                        msg: respone.errorsList
	                    });
	        		}
	        	}else{
	        		alert("查询项目类型失败");
	        	}
	        },error:function(respone){
	            alert("请求发生错误:"+respone);
	        }
		});
		var platetypes= [{"platform_type":"1","plateName":"Web"},{"platform_type":"2","plateName":"Android"},{"platform_type":"3","plateName":"ios"}];
		$.each(platetypes,function(index,platetype){
			if(platetype.platform_type==platform_type){
				plateOptions = plateOptions+"<option selected value='"+platetype.platform_type+"'>"+platetype.plateName+"</option>";
			}else{
				plateOptions = plateOptions+"<option value='"+platetype.platform_type+"'>"+platetype.plateName+"</option>";
			}
		});
		var testOptions = "";
		var testTypes= [{"test_type":"1","testTypeName":"Robotium"},{"test_type":"3","testTypeName":"Macaca"},{"test_type":"4","testTypeName":"selenium"}];
		$.each(testTypes,function(index,testType){
			if(testType.test_type==test_type){
				testOptions = testOptions+"<option selected value='"+testType.test_type+"'>"+testType.testTypeName+"</option>";
			}else{
				testOptions = testOptions+"<option value='"+testType.test_type+"'>"+testType.testTypeName+"</option>";
			}
		});
		//修改项目信息
		
		var typeHtml = "<div class='input-group input-group-lg'><span class='input-group-addon' id='sizing-addon1'>项目类型</span>"+
			"<select class='selectpicker' data-style='btn-info' style='height:46px;width:300px;' id='ciprojectType'><option value=''>请选择项目类型</option>"+options;
		var plateformHtml = "<div class='input-group input-group-lg'><span class='input-group-addon' id='sizing-addon1'>平台类型</span>"+
			"<select class='selectpicker' data-style='btn-info' style='height:46px;width:300px;' id='platformType'><option value=''>请选择平台类型</option>"+plateOptions+"</select></div><br>";
		var testTypeHtml = "<div class='input-group input-group-lg'><span class='input-group-addon' id='sizing-addon1'>测试类型</span>"+
		"<select class='selectpicker' data-style='btn-info' style='height:46px;width:300px;' id='testType'><option value=''>请选择测试类型</option>"+testOptions+"</select></div><br>";
		var html = "";
		html="<div class='input-group input-group-lg'><span class='input-group-addon' id='sizing-addon1'>项目名称</span>" +
			"<input type='text' value='"+project_name+"' class='form-control' placeholder='项目名称' aria-describedby='sizing-addon3' style='width:300px;' id='ciprojectTitle'></div><br>"+typeHtml;
		html = html+plateformHtml+testTypeHtml;
		
		var appHtml = "<div class='input-group input-group-lg'><span class='input-group-addon' id='sizing-addon1'>Package</span>" +
			"<input type='text' value='"+project_package+"' class='form-control' placeholder='Package' aria-describedby='sizing-addon3' style='width:300px;' id='ciprojectPackage'></div><br>" +
			"<div class='input-group input-group-lg'> <span class='input-group-addon' id='sizing-addon1'>Activity&nbsp;&nbsp;&nbsp;</span>" +
			" <input type='text' value='"+project_main_activity+"' class='form-control' placeholder='Activity' aria-describedby='sizing-addon3' style='width:300px;' id='ciprojectActivity'></div><br>";
		
		var webHtml = "<div class='input-group input-group-lg'><span class='input-group-addon' id='sizing-addon1'>登录地址</span>" +
		"<input type='text' value='"+project_login_url+"' class='form-control' placeholder='登录地址' aria-describedby='sizing-addon3' style='width:300px;' id='projectLoginUrl'></div><br>";
		
		var des = "<div class='input-group input-group-lg'> <span class='input-group-addon' id='sizing-addon1'>项目描述</span>" +
			"<div class='form-group'> <textarea class='form-control' rows='3' placeholder='项目描述内容' style='width:300px;' id='ciprojectDesc'>"+project_desc+"</textarea></div></div>";
		if(platform_type=="1"){
			html = html+webHtml+des;
			$("#project_detail").html(html);
		}else{
			html = html+appHtml+des;
			$("#project_detail").html(html);
		}
	};
	
	var _updateEnvironmentType = function(environment_type,project_type){
		//查询项目类型信息
		var params = {};
		var path=contextPath + "/project/queryProjectType";
		var projectTypeList = "";
		if(project.index.productParams.projectType==""||project.index.productParams.projectType.length==0){
			$.ajax({
				type:"POST",
		        url:path,
		        data:JSON.stringify(params),
		        contentType:"application/json; charset=utf-8",
		        dataType: "json",
		        async:false,
		        success:function(response){
		        	if(response.code=="0"){
		        		projectTypeList = response.typeList;
		        	}else{
		        		 alert("查询项目类型失败");
		        	}
		        },error:function(response){
		            alert("请求发生错误:"+response);
		        }
			});
		}
		var options = "<option selected value=''>请选择项目类型</option>";
		if($("#updateEnviromentType").is(':checked')==true){
			$.each(projectTypeList,function(index,list){
				if(list.environment_type&&list.environment_type=="0"){
					if(project_type==list.share_project_type){
						options = options+"<option selected value='"+list.share_project_type+"'>"+list.share_project_name+"</option>";
					}else{
						options = options+"<option value='"+list.share_project_type+"'>"+list.share_project_name+"</option>";
					}
				}
			});
		}else{
			$.each(projectTypeList,function(index,list){
				if(list.environment_type&&list.environment_type=="1"){
					if(project_type==list.share_project_type){
						options = options+"<option selected value='"+list.share_project_type+"'>"+list.share_project_name+"</option>";
					}else{
						options = options+"<option value='"+list.share_project_type+"'>"+list.share_project_name+"</option>";
					}
				}
			});
		}
		$("#ciprojectType").html(options);
	}
	//查询已存在的项目信息
	var _queryTheProject = function(projectId){
		var params = {"projectId":projectId};
		var path = contextPath+"/project/queryTheProject";
	
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "json",
	        async:false,
	        success:function(respone){
	        	if(respone){
	        		if(respone.code==0){
	        			//跳转到项目列表界面
	        			project.index.productParams.resProject = respone.projectMap;
	        		}else{
	        			Lobibox.alert('error', {
	                        msg: respone.errorsList
	                    });
	        		}
	        	}else{
	        		alert("查询项目类型失败");
	        	}
	        },error:function(respone){
	            alert("请求发生错误:"+respone);
	        }
		});
	};
	/**
	 * 修改项目提交
	 */
	_saveProjectInfo = function(){
		
		var ciprojectType = $("#ciprojectType").val();
		var ciprojectTitle = $("#ciprojectTitle").val();
		var ciprojectPackage = $("#ciprojectPackage").val();
		var ciprojectActivity = $("#ciprojectActivity").val();
		var ciprojectDesc = $("#ciprojectDesc").val();
		var ciprojectId = $("#projectId").val();
		var projectLoginUrl = $("#projectLoginUrl").val();
		var platformType = $("#platformType").val();
		var testType = $("#testType").val();
		var params = {
				"ciprojectId":ciprojectId,
				"ciprojectType":ciprojectType,
				"ciprojectTitle":ciprojectTitle,
				"ciprojectPackage":ciprojectPackage,
				"ciprojectActivity":ciprojectActivity,
				"ciprojectDesc":ciprojectDesc,
				"platformType":platformType,
				"testType":testType,
				"projectLoginUrl":projectLoginUrl
				};
		var path = contextPath+"/project/saveProjectInfo";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "json",
	        async:false,
	        success:function(respone){
	        	if(respone){
	        		if(respone.code==0){
	        			//关闭窗口
	        			$('#modifyModal').modal('hide');
	        			//跳转到项目列表界面
	        			Lobibox.alert('success', {
	    		            msg: "项目信息修改成功"
	    		        });
	        			//调至项目列表界面
	        			window.location.href = contextPath + "/user/home";
	        		}else{
	        			Lobibox.alert('error', {
	                        msg: respone.errorsList
	                    });
	        		}
	        	}else{
	        		alert("保存失败失败");
	        	}
	        },error:function(respone){
	            alert("请求发生错误:"+respone);
	        }
		});
	};
	/**
	 * 删除项目
	 */
	_delModel = function(projectId,projectTitle){
		$("#projectId").val(projectId);
		$("#delModalLabel").text(projectTitle);
	};
	/**
	 * 删除项目提交
	 */
	_deleteProjectById = function(){
		var projectId = $("#projectId").val();
		var params = {
				"projectId":projectId
		};
		var path = contextPath+"/project/deleteProjectById";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "json",
	        async:false,
	        success:function(respone){
	        	$("#delModal").modal('hide');
	        	if(respone){
	        		if(respone.code==0){
	        			Lobibox.alert('success', {
	    		            msg: "项目信息删除成功"
	    		        });
	        			//刷新项目列表界面
	        			project.index.changeFunction("project_1","/project/totalProject");
	        		}else{
	        			Lobibox.alert('error', {
	                        msg: respone.errorsList
	                    });
	        		}
	        	}else{
	        		alert("删除项目失败");
	        	}
	        },error:function(respone){
	            alert("请求发生错误:"+respone);
	        }
		});
	};
	//切换界面左侧功能菜单
	var _changeFunction = function(id,tab){
		//判断是否为js函数
		if(typeof $.ecOverlay==undefined){
			window.location.href = contextPath + "/user/login";
			return;
		}
		var $flis = $("#functions ul").find("li");
		$.each($flis,function(index,li){
			if($(li).hasClass("active")){
				$(li).removeClass("active");
			}
		});
		var path = "";
		var params= {};
		$("#"+id).addClass("active");
		//功能请求
		if(tab=="/project/totalProject"){//我的项目
			path = contextPath + "/project/totalProject";
			if($.fn.bootstrapPaginator==undefined){
				window.location.href = contextPath + "/user/index";
				return;
			}else{
				$.fn.bootstrapPaginator.defaults.flag = "0";
			}
			params = {
				"currentPage":project.index.productParams.currentPage,
				"pageSize":project.index.productParams.pageSize
			};
		}else if(tab=="/project/createProject"){//创建项目
			path = contextPath + "/project/createProject";
		}else if(tab=="/project/queryOnlineProject"){
			path = contextPath + "/project/queryOnlineProject";
		}else if(tab=="/project/queryProjectApply"){//我的申请
			path = contextPath + "/project/queryProjectApply";
		}else if(tab=="/project/projectApplyDeal"){//待审批的申请
			path = contextPath + "/project/projectApplyDeal";
		}else if(tab=="/project/totalScript"){
			$.fn.bootstrapPaginator.defaults.flag = "4";
			path = contextPath + "/project/totalScript";
			params = {
					"currentPage":project.index.productParams.scriptCurrentPage,
					"pageSize":project.index.productParams.pageSize
				};
		}else if(tab=="/apk/totalApk"){
			path = contextPath + "/apk/totalApk";
			$.fn.bootstrapPaginator.defaults.flag = "3";
			params = {
				"currentPage":project.index.productParams.apkCurrentPage,
				"pageSize":project.index.productParams.pageSize
			};
			//window.location.href = contextPath + "/apk/totalApk";
		}else if(tab=="/testApk/totalTestApk"){
			path = contextPath + "/testApk/totalTestApk";
			$.fn.bootstrapPaginator.defaults.flag = "5";
			params = {
				"currentPage":project.index.productParams.testApkCurrentPage,
				"pageSize":project.index.productParams.pageSize
			};
		}else if(tab=="/manage/document"){
			path = contextPath + "/manage/document";
			params = {
				"currentPage":project.index.productParams.docCurrentPage,
				"pageSize":project.index.productParams.pageSize
			};
		}else if(tab=="/user/applyAuthority"){
			path = contextPath + "/user/applyAuthority";
		}else if(tab=="/report/index"){
			path = contextPath + "/report/index";
		}else if(tab=="/project/webProject"){
			path = contextPath + "/project/webProject";
			params = {
					"currentPage":project.index.productParams.testWebCurrentPage,
					"pageSize":project.index.productParams.pageSize
				};
		}else{
			path = contextPath + "/user/dealAuthority";
		}
		
		if(tab=="/report/index"){
			window.location.href = contextPath + "/report/index";
		}else{
			$.ajax({
				type:"POST",
		        url:path,
		        data:JSON.stringify(params),
		        contentType:"application/json; charset=utf-8",
		        dataType: "html",
		        async:false,
		        /*beforeSend:function(request){
	    			$.ecOverlay("正在加载中...");
		        },*/
		        success:function(response){
		        	if(response){
		        		if(response.indexOf("registerLabel")>0){
		        			$("#main_body").html(response);
		        		}else{
		        			$("#main_content").html(response);
		        		}
		        		if(tab=="/project/totalProject"&&project.index.productParams.totalPages>0){
		        			var options = {
		        	                size:"large",
		        	                bootstrapMajorVersion:3,
		        	                currentPage: project.index.productParams.currentPage,
		        	                numberOfPages: project.index.productParams.numberOfPages,
		        	                totalPages:project.index.productParams.totalPages
		        	            };
	        	            var element = $('#bp-3-element-lg');
	        	            element.bootstrapPaginator(options);
		        		}
		        		if(tab=="/apk/totalApk"&&project.index.productParams.totalPages>0){
		        			//展示发起测试功能
		        			/*if(user.info.userdata.roleIds!=""){
		        				var roleIds = user.info.userdata.roleIds.split(",");
		        				$.each(roleIds,function(index,roleId){
		        					if(roleId=="2"){
		        						$("#beginTestScriptBtn").removeClass("btn-hidden");
		        					}
		        				});
		        			}*/
		        			//展示分页
		        			var options = {
		        	                size:"large",
		        	                bootstrapMajorVersion:3,
		        	                currentPage: project.index.productParams.apkCurrentPage,
		        	                numberOfPages: project.index.productParams.numberOfPages,
		        	                totalPages:project.index.productParams.totalPages
		        	            };
	        	            var element = $('#bp-3-element');
	        	            element.bootstrapPaginator(options);
		        		}
		        		if(tab=="/project/totalScript"&&project.index.productParams.totalPages>0){
		        			//展示发起测试功能
		        			/*if(user.info.userdata.roleIds!=""){
		        				var roleIds = user.info.userdata.roleIds.split(",");
		        				$.each(roleIds,function(index,roleId){
		        					if(roleId=="2"){
		        						$("#beginTestScriptBtn").removeClass("btn-hidden");
		        					}
		        				});
		        			}*/
		        			//展示分页
		        			var options = {
		        	                size:"large",
		        	                bootstrapMajorVersion:3,
		        	                currentPage: project.index.productParams.scriptCurrentPage,
		        	                numberOfPages: project.index.productParams.numberOfPages,
		        	                totalPages:project.index.productParams.totalPages
		        	            };
	        	            var element = $('#bp-3-element-script');
	        	            element.bootstrapPaginator(options);
		        		}
		        		if(tab=="/testApk/totalTestApk"&&project.index.productParams.totalPages>0){
		        			//展示分页
		        			var options = {
		        	                size:"large",
		        	                bootstrapMajorVersion:3,
		        	                currentPage: project.index.productParams.testApkCurrentPage,
		        	                numberOfPages: project.index.productParams.numberOfPages,
		        	                totalPages:project.index.productParams.totalPages
		        	            };
	        	            var element = $('#bp-3-element-testapk');
	        	            element.bootstrapPaginator(options);
		        		}
		        		if(tab=="/project/webProject"&&project.index.productParams.totalPages>0){
		        			//展示分页
		        			var options = {
		        	                size:"large",
		        	                bootstrapMajorVersion:3,
		        	                currentPage: project.index.productParams.testWebCurrentPage,
		        	                numberOfPages: project.index.productParams.numberOfPages,
		        	                totalPages:project.index.productParams.totalPages
		        	            };
	        	            var element = $('#bp-3-element-webProject');
	        	            element.bootstrapPaginator(options);
		        		}
		        		if(tab=="/manage/document"&&project.index.productParams.totalPages>0){
		        			//展示分页
		        			var options = {
		        	                size:"large",
		        	                bootstrapMajorVersion:3,
		        	                currentPage: project.index.productParams.docCurrentPage,
		        	                numberOfPages: project.index.productParams.numberOfPages,
		        	                totalPages:project.index.productParams.totalPages
		        	            };
	        	            var element = $('#bp-doc-element');
	        	            element.bootstrapPaginator(options);
		        		}
		        		if(project.index.productParams.totalPages>0){
		        			$.unecOverlay();
		        		}
		        	}else{
		        		Lobibox.alert('error', {
		                    msg: "请求失败"
		                });
		        	}
		        },error:function(response){
		            alert("请求发生错误:"+response);
		        }
			});
		}		
	
	};
	//返回脚本树编辑首页
	var _showTreePage = function(projectid){
		/*var params = {
			"projectid":projectid
		};
		var path = contextPath + "/project/showTreePage";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "html",
	        async:false,
	        beforeSend:function(request){
	        	$.ecOverlay("正在加载中...");
	        },
	        success:function(response){
	        	if(response){
	        		console.log("success");
	        	}else{
	        		alert("加载脚本结构信息失败");
	        	}
	        	$.unecOverlay();
	        },error:function(response){
	            alert("加载脚本结构请求发生异常");
	            $.unecOverlay();
	        }
		});*/
		window.location.href = contextPath+"/project/showTreePage?projectid="+projectid;
		/*var params = {"projectid":projectid};
		var path = contextPath + "/project/showTreePage";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "html",
	        async:false,
	        beforeSend:function(request){
	        	$.ecOverlay("正在加载中...");
	        },
	        success:function(response){
	        	if(response){
	        		$("#container-fluid").html(response);
	        	}
	        	 $.unecOverlay();
	        },error:function(response){
	            Lobibox.alert('error', {
                    msg: "获取脚本请求发生异常"
                });
	            $.unecOverlay();
	        }
		});*/
		
	};
	//发起测试界面初始化
	var _initTestScripts = function(param){
		/*if(project.index.productParams.apkId==""){
			alert("请选择需要测试的apk");
			$("#beginToTestScript").modal('hide');
			return;
		}*/
		var platformType = $(param).attr("title");
		var projectId = $(param).attr("id");
		var params = {};
		//判断是否是web项目
		if(platformType=="1"){
			project.index.productParams.platformType = platformType;
			params = {"projectId":projectId,"platformType":platformType};
		}else{
			project.index.productParams.apkId = $(param).attr("name");
		}
		var path = contextPath + "/project/initTestScripts";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "html",
	        async:false,
	        beforeSend:function(request){
	        	$.ecOverlay("正在加载中...");
	        },
	        success:function(response){
	        	if(response){
	        		var $scripts = "<option value=''>请选择测试脚本</option>";
	        		var data = JSON.parse(response);
	        		$.each(data.scriptsList,function(index,script){
	        			$scripts = $scripts + "<option value='"+script.scriptId+","+script.projectId+"'>"+script.scriptName+" - "+script.scriptVersion+"</option>";
	        		});
	        		$("#testScriptOps").html($scripts);
	        	}else{
	        		Lobibox.alert('error', {
	                    msg: "获取项目脚本失败"
	                });
	        	}
	        	$.unecOverlay();
	        },error:function(response){
	            Lobibox.alert('error', {
                    msg: "获取脚本请求发生异常"
                });
	            $.unecOverlay();
	        }
		});
	};
	//开始测试任务
	var _startToScriptTask = function(){
		if(project.index.productParams.platformType==""&&project.index.productParams.platformType!="1"){//判断是否是web项目脚本请求
			if(project.index.productParams.apkId==""){
				alert("请选择需要测试的apk");
				return;
			}
		}
		var scriptId = $("#testScriptOps").find("option:selected").val();
		var params = {
			"apkId":project.index.productParams.apkId,
			"scriptId":scriptId
		};
		var path = contextPath + "/project/startToScriptTask";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "json",
	        async:true,
	        beforeSend:function(request){
	        	$.ecOverlay("正在加载中...");
	        	var inter;
				Lobibox.progress({
					title : '请耐心等待',
					label : '正在上传测试文件到远程服务器......',
					onShow : function($this) {
						var i = 0;
						inter = setInterval(function() {
							window.console.log(i);
							if (i > 100) {
								inter = clearInterval(inter);
							}
							i = i + 0.1;
							$this.setProgress(i);
						}, 120);
					},
					closed : function() {
						inter = clearInterval(inter);
					}
				});
				$("#beginToTestScript").modal('hide');
	        	$.unecOverlay();
	        },
	        success:function(response){
	        	if(response&&response.code=="0"){
	        		Lobibox.alert('success', {
			            msg: response.msg
			        });
	        	}else{
	        		Lobibox.alert('error', {
	                    msg: response.msg
	                });
	        	}
	        	$("#beginToTestScript").modal('hide');
	        	$.unecOverlay();
	        },error:function(response){
	            Lobibox.alert('error', {
                    msg: "测试任务失败请求发生异常"
                });
	            $("#beginToTestScript").modal('hide');
	            $.unecOverlay();
	        }
		});
	};
	//删除apk初始化
	var _initDelScripts = function(pthis){
		$tds = $("#apkTbody").find("tr td input");
		/*if($(pthis).find("td input").is(':checked')){
			project.index.productParams.apkId = "";
			$(pthis).find("td input").prop("checked",false);
		}else{
			$(pthis).find("td input").prop("checked",true);
			project.index.productParams.apkId = $(pthis).attr("id");
		}*/
		var checkedFlag = false;
		$.each($tds,function(index,$td){
			if($($td).is(':checked')&&$td==pthis){
				project.index.productParams.apkId = $(pthis).attr("id");
				checkedFlag = true;
			}else{
				$($td).prop("checked", false);
			}
		});
		if(!checkedFlag){
			project.index.productParams.apkId = "";
		}
	};
	//删除apk初始化信息
	var _initDelAPKModal = function(ths){
		project.index.productParams.apkId = $(ths).attr("id");
		$("#delApkModal").modal("show");
	};
	//删除APK信息
	var _deleteApkById = function(){
		
		var params = {
			"apkId":project.index.productParams.apkId
		};
		var path = contextPath + "/apk/deleteApkById";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "html",
	        async:false,
	        beforeSend:function(request){
	        	$.ecOverlay("正在加载中...");
	        },
	        success:function(response){
	        	$("#delApkModal").modal("hide");
	        	if(response){
	        		Lobibox.alert('success', {
			            msg: "apk信息删除成功"
			        });
	        		project.index.productParams.apkId="";//删除成功，重新置空
	        		project.index.queryTotalApkInfo();
	        	}else{
	        		Lobibox.alert('error', {
	                    msg: "apk信息删除失败"
	                });
	        	}
	        	$.unecOverlay();
	        },error:function(response){
	            Lobibox.alert('error', {
                    msg: "删除apk请求发生异常"
                });
	            $.unecOverlay();
	        }
		});
	};
	//重新加载apk信息列表
	var _queryTotalApkInfo = function(){
		
		$.fn.bootstrapPaginator.defaults.flag = "3";
		var params = {
			"currentPage":project.index.productParams.apkCurrentPage,
			"pageSize":project.index.productParams.pageSize
		};
		var path = contextPath + "/apk/totalApk";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "html",
	        async:false,
	        beforeSend:function(request){
	        	$.ecOverlay("正在加载中...");
	        },
	        success:function(response){
	        	if(response){
	        		$("#main_content").html(response);
	    			//展示分页,判断是否有记录，若没有记录则不执行以下逻辑
	        		if(project.index.productParams.totalPages>0){
	        			var options = {
		    	                size:"large",
		    	                bootstrapMajorVersion:3,
		    	                currentPage: project.index.productParams.apkCurrentPage,
		    	                numberOfPages: project.index.productParams.numberOfPages,
		    	                totalPages:project.index.productParams.totalPages
		    	            };
			            var element = $('#bp-3-element');
			            element.bootstrapPaginator(options);
	        		}
	        		$.unecOverlay();
	        	}else{
	        		Lobibox.alert('error', {
	                    msg: "查询apk信息失败"
	                });
	        	}
	        },error:function(response){
	            alert("请求发生错误:"+response);
	        }
		});
	};
	//删除文件初始化信息
	var _initDelDocModal = function(ths){
		project.index.productParams.documentId = $(ths).attr("id");
		$("#delDocModal").modal("show");
	};
	//删除文件信息
	var _deleteDocById = function(){
		
		var params = {
			"documentId":project.index.productParams.documentId
		};
		var path = contextPath + "/manage/deleteDocById";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "html",
	        async:false,
	        beforeSend:function(request){
	        	$.ecOverlay("正在加载中...");
	        },
	        success:function(response){
	        	$("#delDocModal").modal("hide");
	        	if(response){
	        		Lobibox.alert('success', {
			            msg: "apk信息删除成功"
			        });
	        		project.index.productParams.documentId="";//删除成功，重新置空
	        		project.index.queryTotalDocument();
	        	}else{
	        		Lobibox.alert('error', {
	                    msg: "文件信息删除失败"
	                });
	        	}
	        	$.unecOverlay();
	        },error:function(response){
	            Lobibox.alert('error', {
                    msg: "删除文件请求发生异常"
                });
	            $.unecOverlay();
	        }
		});
	};
	//重新加载文件信息列表
	var _queryTotalDocument = function(){
		var params = {
			"currentPage":project.index.productParams.docCurrentPage,
			"pageSize":project.index.productParams.pageSize
		};
		var path = contextPath + "/manage/document";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "html",
	        async:false,
	        beforeSend:function(request){
	        	$.ecOverlay("正在加载中...");
	        },
	        success:function(response){
	        	if(response){
	        		$("#main_content").html(response);
	    			//展示分页,判断是否有记录，若没有记录则不执行以下逻辑
	        		if(project.index.productParams.totalPages>0){
	        			var options = {
		    	                size:"large",
		    	                bootstrapMajorVersion:3,
		    	                currentPage: project.index.productParams.docCurrentPage,
		    	                numberOfPages: project.index.productParams.numberOfPages,
		    	                totalPages:project.index.productParams.totalPages
		    	            };
			            var element = $('#bp-doc-element');
			            element.bootstrapPaginator(options);
	        		}
	        		$.unecOverlay();
	        	}else{
	        		Lobibox.alert('error', {
	                    msg: "查询文件信息失败"
	                });
	        	}
	        },error:function(response){
	            alert("请求发生错误:"+response);
	        }
		});
	};
	//查询可申请的项目
	var _queryOnlineProject = function(){
		var params = {};
		var path = contextPath + "/project/queryOnlineProject";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "html",
	        async:false,
	        beforeSend:function(request){
	        	$.ecOverlay("正在加载中...");
	        },
	        success:function(response){
	        	if(response){
	        		$("#main_content").html(response);
	        		$.unecOverlay();
	        	}else{
	        		Lobibox.alert('error', {
	                    msg: "删除项目信息失败"
	                });
	        	}
	        },error:function(response){
	            alert("请求发生错误:"+response);
	        }
		});
	};
	//申请项目权限
	var _applyForProject = function(projectId,proUserId){
		var params = {
			"projectId":projectId,
			"proUserId":proUserId  //项目归属人
		};
		var path = contextPath + "/project/applyForProject";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "json",
	        async:false,
	        success:function(response){
	        	if(response){
	        		Lobibox.alert('success', {
			            msg: "申请项目成功"
			        });
	        		//重载申请项目
	        		project.index.queryOnlineProject();
	        	}else{
	        		Lobibox.alert('error', {
	                    msg: "项目申请失败"
	                });
	        	}
	        },error:function(response){
	            alert("请求发生错误:"+response);
	        }
		});
	};
	//拒绝审批项目权限通过
	var _refuseForProject = function(applyId,projectId,userId,belongUserId){
		var params = {
			"applyId":applyId,
			"projectId":projectId,
			"userId":userId,
			"belongUserId":belongUserId
		};
		var path = contextPath + "/project/refuseForProject";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "json",
	        async:false,
	        success:function(response){
	        	if(response&&response.code=="0"){
	        		$("#main_content").html(response);
	        		//重新加载
	        		project.index.projectApplyDeal();
	        	}else{
	        		Lobibox.alert('error', {
	                    msg: "加载项目审批信息失败"
	                });
	        	}
	        },error:function(response){
	            alert("请求发生错误:"+response);
	        }
		});
	};
	//同意项目申请通过
	var _acceptForProject = function(applyId,projectId,userId,belongUserId){
		var params = {
				"applyId":applyId,
				"projectId":projectId,
				"userId":userId,
				"belongUserId":belongUserId
			};
			var path = contextPath + "/project/acceptForProject";
			$.ajax({
				type:"POST",
		        url:path,
		        data:JSON.stringify(params),
		        contentType:"application/json; charset=utf-8",
		        dataType: "json",
		        async:false,
		        success:function(response){
		        	if(response&&response.code=="0"){
		        		$("#main_content").html(response);
		        		//重新加载
		        		project.index.projectApplyDeal();
		        	}else{
		        		Lobibox.alert('error', {
		                    msg: "审批项目信息失败"
		                });
		        	}
		        },error:function(response){
		            alert("请求发生错误:"+response);
		        }
			});
	};
	//重新加载待审批的项目信息
	var _projectApplyDeal = function(){
		var params = {};
		var path = contextPath+"/project/projectApplyDeal";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "html",
	        async:false,
	        success:function(response){
	        	if(response){
	        		$("#main_content").html(response);
	        	}else{
	        		Lobibox.alert('error', {
	                    msg: "加载项目审批信息失败"
	                });
	        	}
	        },error:function(response){
	            alert("请求发生错误:"+response);
	        }
		});
	}
	//查询用户可申请的权限信息
	var _applyForAuthority = function(roleId,roleName){
		var params = {
				"roleId":roleId,
				"roleName":roleName
			};
			var path = contextPath + "/user/applyForAuthority";
			$.ajax({
				type:"POST",
		        url:path,
		        data:JSON.stringify(params),
		        contentType:"application/json; charset=utf-8",
		        dataType: "json",
		        async:false,
		        success:function(response){
		        	if(response){
		        		Lobibox.alert('success', {
				            msg: "申请权限成功"
				        });
		        		//重载申请项目
		        	}else{
		        		Lobibox.alert('error', {
		                    msg: "权限申请失败"
		                });
		        	}
		        },error:function(response){
		            alert("请求发生错误:"+response);
		        }
			});
	};
	//拒绝申请
	var _refuseForAuthority = function(userId,authId,roleId){
		var params = {
			"authId":authId,
			"userId":userId,
			"roleId":roleId
		};
		var path = contextPath + "/user/refuseForAuthority";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "json",
	        async:false,
	        success:function(response){
	        	if(response&&response.code=="0"){
	        		Lobibox.alert('success', {
			            msg: "拒绝审批权限通过"
			        });
	        		//重载加载审批信息
	        		project.index.dealAuthority();
	        	}else{
	        		alert("拒绝审批权限失败");
	        	}
	        },error:function(response){
	            alert("请求发生错误:"+response);
	        }
		});
	};
	//审批通过
	var _acceptForAuthority = function(userId,authId,roleId){
		var params = {
				"authId":authId,
				"userId":userId,
				"roleId":roleId
			};
		var path = contextPath + "/user/acceptForAuthority";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "json",
	        async:false,
	        success:function(response){
	        	if(response&&response.code=="0"){
	        		Lobibox.alert('success', {
			            msg: "审批权限通过"
			        });
	        		//重载加载审批信息
	        		project.index.dealAuthority();
	        	}else{
	        		alert("审批权限失败");
	        	}
	        },error:function(response){
	            alert("请求发生错误:"+response);
	        }
		});
	};
	//重新加载审批单
	var _dealAuthority = function(){
		var params = {};
		var path = contextPath + "/user/dealAuthority";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "html",
	        async:false,
	        success:function(response){
	        	if(response){
	        		$("#main_content").html(response);
	        	}else{
	        		Lobibox.alert('error', {
	                    msg: "加载审批信息失败"
	                });
	        	}
	        },error:function(response){
	            alert("请求发生错误:"+response);
	        }
		});
	};
	//项目授权界面初始化
	var _initAuthorizedProject = function(ciProjectId,ciProjectTitle){
		//清空原来选择的用户名称信息
		$("#authorizedUserName").val("");
		$("#authorizedUserIds").val("");
		
		$("#authorizedProjectName").val(ciProjectTitle);
		//查询权限信息并初始化
		project.index.queryAuthorizionInfo();
		var $authOps = "<option value=''>请选择权限</option>";
		$.each(project.index.productParams.authorizionList,function(index,authorizion){
			 $authOps = $authOps + "<option value='"+authorizion.project_role_id+"'>"+authorizion.project_role_name+"</option>";
		});
		$("#authorizedOps").html($authOps);
		//选择权限,绑定事件change,改变授权权限，则把授权人员清空
		$("#authorizedOps").bind("change",function(){
			//判断是否选中所有授权的权限信息，是：打开授权人员选择功能；否：授权人员功能禁用
			var authoryName = $(this).find("option:selected").val();
			if(authoryName!=null&&authoryName!=""){
				$("#authorizedUserName").attr("disabled",false);
			}else{
				$("#authorizedUserName").attr("disabled",true);
			}
			$("#authorizedUserName").val("");
		});
		//初始化选择授权人事件
		$("#authorizedUserName").bind("click",function(){
			project.index.initUserNameInfo();
		});
		$("#ciProjectId").val(ciProjectId);
	};
	//查询项目权限信息
	var _queryAuthorizionInfo = function(){
		var params = {};
		var path = contextPath + "/project/queryAuthorizionInfo";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "json",
	        async:false,
	        success:function(response){
	        	if(response){
	        		project.index.productParams.authorizionList = response;
	        	}else{
	        		Lobibox.alert('error', {
	                    msg: "加载审批信息失败"
	                });
	        	}
	        },error:function(response){
	            alert("请求发生错误:"+response);
	        }
		});
	};
	//查询未授权人信息
	var _initUserNameInfo = function(){
		//判断是否选择了，需要授权的权限信息
		var projectRoleId = $("#authorizedOps").find("option:selected").val();
		if(projectRoleId==""||projectRoleId==null){
			alert("请先选择权限信息");
			return;
		}
		var ciProjectId = $("#ciProjectId").val();
		var params = {
			"ciProjectId":ciProjectId,
			"projectRoleId":projectRoleId
		};
		var path = contextPath + "/project/queryNoAuthForUser";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "json",
	        async:false,
	        success:function(response){
	        	if(response){
	        		//展示客户信息、
	        		var userdatas = response;
	        		var $lis = "";
	        		$.each(userdatas,function(index,userdata){
	        			$lis = $lis + "<li><input type='checkbox' name='"+userdata.userName+"' id='"+userdata.userId+"'>"+userdata.userName+"</li>";
	        		});
	        		$("#userNameLi").html($lis);
	        	}else{
	        		Lobibox.alert('error', {
	                    msg: "加载用户信息失败"
	                });
	        		 $("#authorizedUserModal").modal("hide");
	        	}
	        },error:function(response){
	            alert("请求发生错误:"+response);
	            $("#authorizedUserModal").modal("hide");
	        }
		});
	};
	//将选择的授权人填入授权项目input框中
	var _selectedUserName = function(){
		var $lis = $("#userNameLi").find("li input");
		//定义存放名称的变量
		var userNames = "";
		var userIds = "";
		var checkidLis = new Array();
		$.each($lis,function(index,$li){
			if($($li).is(":checked")){
				checkidLis.push($li)
			}
		});
		$.each(checkidLis,function(i,checkedLi){
			if(i==checkidLis.length-1){
				userNames = userNames + $(checkedLi).attr("name")
				userIds = userIds +$(checkedLi).attr("id");
			}else{
				userNames = userNames + $(checkedLi).attr("name")+ ",";
				userIds = userIds +$(checkedLi).attr("id")+ ",";
			}
		});
		$("#authorizedUserName").val(userNames);
		$("#authorizedUserIds").val(userIds);
		$("#authorizedUserModal").modal('hide');
	};
	//项目授权提交
	var _authorizedProject = function(){
		var userIds = $("#authorizedUserIds").val();
		if(userIds==""||userIds==null){
			alert("授权用户名称不能为空");
			return;
		}
		var projectRoleId = $("#authorizedOps").find("option:selected").val();
		if(projectRoleId==""||projectRoleId==null){
			alert("授权权限不能为空");
			return;
		}
		var ciProjectId = $("#ciProjectId").val();
		var params = {
			"userIds":userIds,
			"projectRoleId":projectRoleId,
			"ciProjectId":ciProjectId
		};
		var path = contextPath + "/project/authorizedProject";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "json",
	        async:false,
	        success:function(response){
	        	if(response){
	        		Lobibox.alert('success', {
			            msg: "授权成功"
			        });
	        		$("#authorizedProjectModal").modal("hide");
	        	}else{
	        		Lobibox.alert('error', {
	                    msg: "用户授权失败"
	                });
	        		$("#authorizedProjectModal").modal("hide");
	        	}
	        },error:function(response){
	            alert("用户授权请求发生错误:"+response);
	            $("#authorizedProjectModal").modal("hide");
	        }
		});
	};
	//查询授权人
	var _searchUserInfo = function(){
		
		var projectRoleId = $("#authorizedOps").find("option:selected").val();
		if(projectRoleId==""||projectRoleId==null){
			alert("请先选择权限信息");
			return;
		}
		var ciProjectId = $("#ciProjectId").val();
		var userName = $("#searchSubmitInput").val();
		if(userName==null||userName==""){
			alert("请输入用户名称");
			return;
		}
		var params = {
			"userName":userName,
			"projectRoleId":projectRoleId,
			"ciProjectId":ciProjectId
		};
		var path=contextPath + "/project/queryNoAuthForUser";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "json",
	        async:false,
	        success:function(response){
	        	if(response){
	        		//展示客户信息、
	        		var userdatas = response;
	        		var $lis = "";
	        		$.each(userdatas,function(index,userdata){
	        			$lis = $lis + "<li><input type='checkbox' name='"+userdata.userName+"' id='"+userdata.userId+"'>"+userdata.userName+"</li>";
	        		});
	        		$("#userNameLi").html($lis);
	        	}else{
	        		Lobibox.alert('error', {
	                    msg: "加载用户信息失败"
	                });
	        		 $("#authorizedUserModal").modal("hide");
	        	}
	        },error:function(response){
	            alert("请求发生错误:"+response);
	            $("#authorizedUserModal").modal("hide");
	        }
		});
	};
	var _downLoadReport = function(url){
		var url = decodeURI(url)
		window.location.href=url;
	};
	//查询组件信息
	var _constructeModel = function(projectId,projectName){
		var params = {"projectId":projectId,"projectName":projectName};
		var path=contextPath + "/module/buildModule";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "json",
	        async:false,
	        success:function(response){
	        	if(response){
	        		alert("success");
	        	}
	        },error:function(response){
	            alert("请求发生错误:"+response);
	        }
		});
	}
	
	var _traversalApk = function(){
		var path=contextPath + "/project/traversalApk";
		$.ajax({
			type:"POST",
	        url:path,
	        data:"",
	        contentType:"application/json; charset=utf-8",
	        dataType: "json",
	        async:false,
	        success:function(response){
	        	if(response){
	        		alert("success");
	        	}
	        },error:function(response){
	            alert("请求发生错误:"+response);
	        }
		});
	}
	//下载脚本信息
	var _downLoadScript = function(url){
		window.location.href = url;
	}
	//下载文件
	var _downLoadDoc = function(url){
		window.location.href = url;
	}
	//删除脚本信息
	var _delScript = function(scriptId){
		var params = {"scriptId":scriptId};
		var path=contextPath + "/project/delScript";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "json",
	        async:false,
	        success:function(response){
	        	if(response){
	        		//alert("success");
	        		//重新加载脚本信息
	        		$.fn.bootstrapPaginator.defaults.flag = "4";
	    			path = contextPath + "/project/totalScript";
	    			params = {
	    					"currentPage":project.index.productParams.scriptCurrentPage,
	    					"pageSize":project.index.productParams.pageSize
	    				};
	        		$.ajax({
	        			type:"POST",
	        	        url:path,
	        	        data:JSON.stringify(params),
	        	        contentType:"application/json; charset=utf-8",
	        	        dataType: "html",
	        	        async:false,
	        	        beforeSend:function(request){
	        	        	$.ecOverlay("正在加载中...");
	        	        },
	        	        success:function(response){
	        	        	if(response){
	        	        		$("#main_content").html(response);	     
	        	        		$.unecOverlay();
	        	        	}else{
	        	        		Lobibox.alert('error', {
	        	                    msg: "请求失败"
	        	                });
	        	        	}
	        	        },error:function(response){
	        	            alert("请求发生错误:"+response);
	        	        }
	        		});
	        	}
	        },error:function(response){
	            alert("请求发生错误:"+response);
	        }
		});
	}
	var _downLoadTestAPK = function(param){
		window.location.href = param
	}
	var _deleteTestApk = function(testApkId){
		var params = {"testApkId":testApkId};
		var path=contextPath + "/testApk/deleteTestApkById";
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "json",
	        async:false,
	        success:function(response){
	        	if(response){
	        		alert("success");
	        		$.fn.bootstrapPaginator.defaults.flag = "5";
	    			params = {
	    				"currentPage":project.index.productParams.testApkCurrentPage,
	    				"pageSize":project.index.productParams.pageSize
	    			};
	    			path = contextPath + "/testApk/totalTestApk";
	        		$.ajax({
	        			type:"POST",
	        	        url:path,
	        	        data:JSON.stringify(params),
	        	        contentType:"application/json; charset=utf-8",
	        	        dataType: "html",
	        	        async:false,
	        	        beforeSend:function(request){
	        	        	$.ecOverlay("正在加载中...");
	        	        },
	        	        success:function(response){
	        	        	if(response){
	        	        		$("#main_content").html(response);
	        	        		$.unecOverlay();
	        	        	}else{
	        	        		Lobibox.alert('error', {
	        	                    msg: "请求失败"
	        	                });
	        	        	}
	        	        },error:function(response){
	        	            alert("请求发生错误:"+response);
	        	        }
	        		});
	        	}
	        },error:function(response){
	            alert("请求发生错误:"+response);
	        }
		});
	}
	var _checkEnvironmentType = function(){
		//查询项目类型
		var params = {};
		var path=contextPath + "/project/queryProjectType";
		if(project.index.productParams.projectType==""||project.index.productParams.projectType.length==0){
			$.ajax({
				type:"POST",
		        url:path,
		        data:JSON.stringify(params),
		        contentType:"application/json; charset=utf-8",
		        dataType: "json",
		        async:false,
		        success:function(response){
		        	if(response.code=="0"){
		        		project.index.productParams.projectType = response.typeList;
		        	}else{
		        		 alert("查询项目类型失败");
		        	}
		        },error:function(response){
		            alert("请求发生错误:"+response);
		        }
			});
		}
	    if($("input[type='checkbox']").is(':checked')){
	    	var preType = "<option value=''>请选择项目类型</option>";
	    	$.each(project.index.productParams.projectType,function(index,list){
	    		if(list.environment_type=="0"){
	    			preType = preType + "<option value='"+list.share_project_type+"'>"+list.share_project_name+"</option>";
	    		}
	    	});
	    	$("#projectType").html(preType);
	    }else{
	    	var type = "<option value=''>请选择项目类型</option>";
	    	$.each(project.index.productParams.projectType,function(index,list){
	    		if(list.environment_type=="1"){
	    			type = type + "<option value='"+list.share_project_type+"'>"+list.share_project_name+"</option>";
	    		}
	    	});
	    	$("#projectType").html(type);
	    }
	}
	//查询测试apk
	var _searchTestAPK = function(){
		var scriptText = $("#searchText").val();
		if(searchText==null||searchText==""){
			return;
		}
		var path = contextPath + "/testApk/searchTestApk";
		$.fn.bootstrapPaginator.defaults.flag = "5";
		var params = {
			"currentPage":project.index.productParams.testApkCurrentPage,
			"pageSize":project.index.productParams.pageSize,
			"scriptText":scriptText
		};
		
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "html",
	        async:false,
	        /*beforeSend:function(request){
    			$.ecOverlay("正在加载中...");
	        },*/
	        success:function(response){
	        	if(response){
	        		if(response.indexOf("registerLabel")>0){
	        			$("#main_body").html(response);
	        		}else{
	        			$("#main_content").html(response);
	        		}
	        		//展示分页
	        		var options = {
	                        size:"large",
	                        bootstrapMajorVersion:3,
	                        currentPage: project.index.productParams.testApkCurrentPage,
	                        numberOfPages: project.index.productParams.numberOfPages,
	                        totalPages:project.index.productParams.totalPages
	                    };
	                var element = $('#bp-3-element-testapk');
	                element.bootstrapPaginator(options);
	        	}
	        }
		});
	}
	//获取测试报告
	var _queryReporter = function(projectId,projectName){
		window.location.href = contextPath + "/project/repindex?projectId="+projectId;
	}
	
	var _addProjectLoginInfo = function(projectId,projectName,platformType){
		window.location.href = contextPath + "/project/projectuser?projectId="+projectId+"&platformType="+platformType;
	};
	var _initLoginParam = function(param){
		$("#projectId").val($(param).attr("id"));
		$("#projectName").val($(param).attr("name"));
		$("#platformType").val($(param).attr("title"));
	};
	var _saveLoginInfo = function(){
		var projectId = $("#projectId").val();
		var projectName = $("#projectName").val();
		var platformType = $("#platformType").val();
		var organizationId = $("#organizationId").val();
		var loginName = $("#loginName").val();
		var loginPwd = $("#loginPwd").val();
		if(loginName==null||loginName==""){
			alert("请输入账号");
			return;
		}
		if(loginPwd==null||loginPwd==""){
			alert("请输入密码");
			return;
		}
		var path = contextPath + "/project/saveLoginInfo";
		var params = {"projectId":projectId,"projectName":projectName,"platformType":platformType,"organizationId":organizationId,
				"loginName":loginName,"loginPwd":loginPwd};
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "json",
	        async:false,
	        /*beforeSend:function(request){
    			$.ecOverlay("正在加载中...");
	        },*/
	        success:function(response){
	        	if(response&&response.code==0){
	        		Lobibox.alert('success', {
			            msg: "账号信息添加成功"
			        });
	        		$("#addLoginModal").modal("hide");
	        		$("#userInfoDetail").modal("show");
	        	}
	        }
		});
	};
	var _initUpdateInfo = function(param){
		var projectId = $(param).attr("id");
		var platformType = $(param).attr("title");
		var path = contextPath + "/project/initUpdateInfo";
		var params = {"projectId":projectId,"platformType":platformType};
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "json",
	        async:false,
	        success:function(response){
	        	if(response&&response.code==0){
	        		//初始化账户列表
	        		var html= "";
	        		$.each(response.list,function(index,list){
	        			if(index/2==0){
	        				html = html + "<tr class='info'><td><input type='text' style='width:80px;' value='"+list.organizationId+"'></td><td><input type='text' style='width:80px;' value='"+list.loginName+"'></td><td><input type='text' style='width:80px;' value='"+list.loginPwd+"'></td>" +
	        						"<td><button type='button' class='btn btn-primary' onclick='project.index.updateLoginInfo(\""+list.projectUserId+"\",\""+list.organizationId+"\",\""+list.loginName+"\",\""+list.loginPwd+"\");'>修改</button></td></tr>";
	        			}else{
	        				html = html + "<tr class='success'><td><input type='text' style='width:80px;' value='"+list.organizationId+"'></td><td><input type='text' style='width:80px;' value='"+list.loginName+"'></td><td><input type='text' style='width:80px;' value='"+list.loginPwd+"'></td>" +
	        						"<td><button type='button' class='btn btn-primary' onclick='project.index.updateLoginInfo(\""+list.projectUserId+"\",\""+list.organizationId+"\",\""+list.loginName+"\",\""+list.loginPwd+"\");'>修改</button></td></tr>";
	        			}
	        		});
	        		$("#userInfoTBody").html(html);
	        		$("#userInfoDetail").modal("show");
	        	}
	        }
		});
	};
	var _updateLoginInfo = function(projectUserId,organizationId,loginName,loginPwd){
		var path = contextPath + "/project/updateLoginInfo";
		var params = {"projectUserId":projectUserId,"organizationId":organizationId,"loginName":loginName,"loginPwd":loginPwd};
		$.ajax({
			type:"POST",
	        url:path,
	        data:JSON.stringify(params),
	        contentType:"application/json; charset=utf-8",
	        dataType: "json",
	        async:false,
	        success:function(response){
	        	if(response&&response.code==0){
	        		//初始化账户列表
	        		alert("修改用户信息成功");
	        		$("#userInfoDetail").modal("hide");
	        	}
	        }
		});
	};
	return{
		insertProject:_insertProject,
		modifyModel:_modifyModel,
		saveProjectInfo:_saveProjectInfo,
		delModel:_delModel,
		deleteProjectById:_deleteProjectById,
		queryTheProject:_queryTheProject,
		changeFunction:_changeFunction,
		showTreePage:_showTreePage,
		productParams:_productParams,
		initTestScripts:_initTestScripts,
		startToScriptTask:_startToScriptTask,
		initDelScripts:_initDelScripts,
		deleteApkById:_deleteApkById,
		queryTotalApkInfo:_queryTotalApkInfo,
		applyForProject:_applyForProject,
		refuseForProject:_refuseForProject,
		projectApplyDeal:_projectApplyDeal,
		acceptForProject:_acceptForProject,
		queryOnlineProject:_queryOnlineProject,
		applyForAuthority:_applyForAuthority,
		refuseForAuthority:_refuseForAuthority,
		acceptForAuthority:_acceptForAuthority,
		dealAuthority:_dealAuthority,
		initAuthorizedProject:_initAuthorizedProject,
		queryAuthorizionInfo:_queryAuthorizionInfo,
		authorizedProject:_authorizedProject,
		initUserNameInfo:_initUserNameInfo,
		selectedUserName:_selectedUserName,
		searchUserInfo:_searchUserInfo,
		downLoadReport:_downLoadReport,
		initDelAPKModal:_initDelAPKModal,
		constructeModel:_constructeModel,
		downLoadScript:_downLoadScript,
		delScript:_delScript,
		downLoadTestAPK:_downLoadTestAPK,
		deleteTestApk:_deleteTestApk,
		checkEnvironmentType:_checkEnvironmentType,
		updateEnvironmentType:_updateEnvironmentType,
		searchTestAPK:_searchTestAPK,
		queryReporter:_queryReporter,
		addProjectLoginInfo:_addProjectLoginInfo,
		initLoginParam:_initLoginParam,
		saveLoginInfo:_saveLoginInfo,
		initUpdateInfo:_initUpdateInfo,
		updateLoginInfo:_updateLoginInfo,
		queryTotalDocument:_queryTotalDocument,
		downLoadDoc:_downLoadDoc,
		initDelDocModal:_initDelDocModal,
		deleteDocById:_deleteDocById
	};
})();
$(function(){
	$("#user-info").show();
	$("#adminUserName").text(adminUserName);
	/*var roleIds = user.info.userdata.roleIds.split(",");
	$.each(roleIds,function(index,roleId){
		if(roleId=="3"){
			$("#project_7").hide();
			$("#project_5").show();
			$("#project_8").show();
		}
	});*/
});